package com.ruoyi.im.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.im.domain.CssChatSession;
import com.ruoyi.im.service.ICssChatSessionService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 聊天会话Controller
 *
 * @author zzh
 * @date 2024-10-18
 */
@RestController
@RequestMapping("/system/chat-session")
@Api(tags = "聊天会话")
public class CssChatSessionController extends BaseController
{
    @Autowired
    private ICssChatSessionService cssChatSessionService;

    /**
     * 查询聊天会话列表
     */
    @PreAuthorize("@ss.hasPermi('system:chatsession:list')")
    @GetMapping("/list")
    public TableDataInfo list(CssChatSession cssChatSession)
    {
        startPage();
        List<CssChatSession> list = cssChatSessionService.selectCssChatSessionList(cssChatSession);
        return getDataTable(list);
    }

    /**
     * 导出聊天会话列表
     */
    @PreAuthorize("@ss.hasPermi('system:chatsession:export')")
    @Log(title = "聊天会话", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CssChatSession cssChatSession)
    {
        List<CssChatSession> list = cssChatSessionService.selectCssChatSessionList(cssChatSession);
        ExcelUtil<CssChatSession> util = new ExcelUtil<CssChatSession>(CssChatSession.class);
        util.exportExcel(response, list, "聊天会话数据");
    }

    /**
     * 获取聊天会话详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:chatsession:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(cssChatSessionService.selectCssChatSessionById(id));
    }

    /**
     * 新增聊天会话
     */
    @PreAuthorize("@ss.hasPermi('system:chatsession:add')")
    @Log(title = "聊天会话", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CssChatSession cssChatSession)
    {
        return toAjax(cssChatSessionService.insertCssChatSession(cssChatSession));
    }

    /**
     * 修改聊天会话
     */
    @PreAuthorize("@ss.hasPermi('system:chatsession:edit')")
    @Log(title = "聊天会话", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CssChatSession cssChatSession)
    {
        return toAjax(cssChatSessionService.updateCssChatSession(cssChatSession));
    }

    /**
     * 删除聊天会话
     */
    @PreAuthorize("@ss.hasPermi('system:chatsession:remove')")
    @Log(title = "聊天会话", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(cssChatSessionService.deleteCssChatSessionByIds(ids));
    }
}
